//
//  ViewController.m
//  KVO
//
//  Created by clz on 2019/7/21.
//  Copyright © 2019年 clz. All rights reserved.
//

#import "ViewController.h"
#import "Persion.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Persion *xiaoMing = [[Persion alloc]init];
    
    [xiaoMing addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
    [xiaoMing addObserver:self forKeyPath:@"age" options:NSKeyValueObservingOptionNew context:nil];
    xiaoMing.name = @"xiaomingming";
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    NSLog(@"进来了");
    id value = change[NSKeyValueChangeNewKey];
    
    if ([keyPath isEqualToString:@"name"]) {
        NSLog(@"value= %@",value);
    }else if([keyPath isEqualToString:@"age"]){
        
    }
}


@end
